<?php
/**
 * User: 1971229701@qq.com
 * Date: 2020/11/2/002
 * Time: 15:21
 */

namespace app\admin\controller;


use app\common\model\Admin;
use think\Controller;
use think\facade\Session;
use think\Request;

class Login extends Controller
{
    public function do_login(Request $request)
    {
        if ($request->isPost()) {
            $data = $request->post();
            $where = [
                'username' => $data['username'],
            ];
            $r = Admin::get($where);

            if (!$r)
                return apiReturnFail("账号不存在！");

            if (!password_verify($data['password'], $r['password']))
                return apiReturnFail('密码错误！');

            Session::set('admin_info',$r);
            return apiReturnSuc();
        } else {
            return $this->fetch();
        }
    }

    public function login_out()
    {
        Session::delete('admin_info');

        return $this->fetch('login/do_login');
    }
}